PowerTCP Emulation for .NET
Read(Byte[]) Method
Example 




The byte array used to store the received data.
Receives data from the remote host.
Syntax
Public Overloads Function Read( _
   ByVal buffer() As Byte _
) As Data
Dim instance As TcpBase
Dim buffer() As Byte
Dim value As Data
 
value = instance.Read(buffer)
public Data Read( 
   byte[] buffer
)
public: Data* Read( 
   byte[]* buffer
) 
public:
Data^ Read( 
   array<byte>^ buffer
) 

Parameters

buffer
The byte array used to store the received data.

Return Value

A Data object encapsulating the received data. Returns null if the socket is closed.
Remarks

This method performs a single socket read, blocking until at least one byte is read, up to as much data as is available on the socket or buffer.Length, whichever is lowest.

This method will block until data is available or the ReceiveTimeout has expired.

Example
This example demonstrates execution of a looping Read on a worker thread, and marshaling the data to the UI.
private void button1_Click(object sender, EventArgs e)
{
    myComponent.Start(readLoopWorker, null);
}

private void readLoopWorker(object state)
{
    byte[] buffer = new byte[1024];
    Data data = myComponent.Read(buffer);
    while (data != null)
    {
        myComponent.Marshal(data, "", null);
        data = myComponent.Read(buffer);
    }
    myComponent.Close();
}

void myComponent_Data(object sender, Dart.Sockets.DataEventArgs e)
{
    textBox1.AppendText(e.Data.ToString());
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    myComponent.Start(AddressOf readLoopWorker, Nothing)
End Sub

Private Sub readLoopWorker(ByVal state As Object)
    Dim buffer(1023) As Byte
    Dim data As Data = myComponent.Read(buffer)
    Do While data IsNot Nothing
        myComponent.Marshal(data, "", Nothing)
        data = myComponent.Read(buffer)
    Loop
    myComponent.Close()
End Sub

Private Sub myComponent_Data(ByVal sender As Object, ByVal e As Dart.Sockets.DataEventArgs)
    textBox1.AppendText(e.Data.ToString())
End Sub
See Also

Reference

TcpBase Class
TcpBase Members
Overload List


PowerTCP Emulation for .NET Documentation Version 4.7
© 2018 Dart Communications. All Rights Reserved.
Send comments on this topic